package hadoop.hbase;

/*import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.ipc.Server;

import java.util.ArrayList;
import java.util.List;*/

/**
 * @author qiss
 * @create 2018-04-02 15:46
 **/
public class HbaseDemo {
    /*static Configuration config = null;
    static{
        config = HBaseConfiguration.create();
        config.set("hbase.zookeeper.quorum","hadoop-zk1,hadoop-zk2,hadoop-zk3");
        config.set("hbase.zookeeper.property.clientPort","2181");
        config.set("hbase,master","hadoop-hbase-master");
    }

    *//**
     * 创建表
     * @throws Exception
     *//*
    public void createTable() throws Exception{
        //提供接口关系Hbase数据库中的表信息（表管理类）
        HBaseAdmin admin = new HBaseAdmin(config);
        //包含了表的名字以及表的列族信息，表的schema  （表描述类）
        String tableName = "";
        HTableDescriptor htd = new HTableDescriptor(tableName);
        //列族
        HColumnDescriptor f1 = new HColumnDescriptor("f1");
        HColumnDescriptor f2 = new HColumnDescriptor("f2");
        htd.addFamily(f1);
        htd.addFamily(f2);
        admin.createTable(htd);
    }

    public void deleteTable() throws Exception{
        HBaseAdmin admin = new HBaseAdmin(config);
        String tableName = "";
        admin.disableTable(tableName);
        admin.deleteTable(tableName);
    }

    public void getTable()throws Exception{
        String tableName = "";
        //普通获取表
        HTable hTable = new HTable(config, Bytes.toBytes(tableName));
        //通过连接池获取表(推荐使用)
        HTablePool pool = new HTablePool(config, 10);
        HTableInterface table = pool.getTable(tableName);
    }

    public void putData() throws Exception{
        HTablePool pool = new HTablePool(config, 10);
        HTableInterface table = pool.getTable("");
        //单条insert
        Put rowkey = new Put(Bytes.toBytes("rowkey"));
        rowkey.add(Bytes.toBytes("family"),Bytes.toBytes("qualifiier"),Bytes.toBytes("value"));
        table.put(rowkey);

        //多条insert
        Put rk1 = new Put(Bytes.toBytes("rk1"));
        rk1.add(Bytes.toBytes("family"),Bytes.toBytes("qualifiier"),Bytes.toBytes("value"));
        List<Put> list = new ArrayList<Put>();
        list.add(rk1);
        table.put(list);
    }

    public void deteleData() throws Exception{
        HTablePool pool = new HTablePool(config, 10);
        HTableInterface table = pool.getTable("tableName");
        Delete del = new Delete(Bytes.toBytes("rowkey"));
        table.delete(del);
    }

    public void getData() throws Exception{
        //单条数据
        HTablePool pool = new HTablePool(config, 10);
        HTableInterface table = pool.getTable("tableName");
        Get get = new Get(Bytes.toBytes("rowKey"));
        Result row = table.get(get);
        for (KeyValue keyValue : row.raw()) {
            System.out.println(new String(keyValue.getRow())+"-");
            System.out.println(new String(keyValue.getFamily())+"-");
            System.out.println(new String(keyValue.getQualifier())+"-");
            System.out.println(new String(keyValue.getValue())+"-");
            System.out.println(keyValue.getTimestamp()+"-\n");
        }

        //批量
        Scan scan = new Scan();
        scan.setStartRow("a1".getBytes());
        scan.setStopRow("a20".getBytes());
        ResultScanner scanner = table.getScanner(scan);
        for (Result row1 : scanner) {
            System.out.println("rowkey:"+new String(row1.getRow()));
            for (KeyValue kv : row1.raw()) {
                //同上
            }
        }*/

        //过滤器



    //}





}
